using System;
using Caliburn.Micro;

namespace MediaOwl.Common.Dialog
{
    public class DialogScreen : Screen, IDialog
    {
        #region Properties & Backingfields

        private string dialogMessage;
        public string DialogMessage
        {
            get { return dialogMessage; }
            set
            {
                dialogMessage = value;
                NotifyOfPropertyChange(() => DialogMessage);
            }
        }

        #endregion

        #region Methods

        protected override void OnInitialize()
        {  
            base.OnInitialize();
            //DisplayName = "Dialog";
            DialogMessageResult = DialogResult.None;
        }

        protected override void OnDeactivate(bool close)
        {
            base.OnDeactivate(close);

            if (close)
            {
                Completed(this, new DialogResultEventArgs
                {
                    DialogResult = DialogMessageResult,
                    Error = DialogError
                });
            }
        }

        #endregion

        #region Implementation of IDialog

        private Exception dialogError;
        public Exception DialogError
        {
            get { return dialogError; }
            set
            {
                dialogError = value;
                NotifyOfPropertyChange(() => DialogError);
            }
        }

        private DialogResult dialogMessageResult;
        public DialogResult DialogMessageResult
        {
            get { return dialogMessageResult; }
            set
            {
                dialogMessageResult = value;
                NotifyOfPropertyChange(() => DialogMessageResult);
            }
        }

        private object dialogResultValue;
        public object DialogResultValue
        {
            get { return dialogResultValue; }
            set
            {
                dialogResultValue = value;
                NotifyOfPropertyChange(() => DialogResultValue);
            }
        }

        public event EventHandler<DialogResultEventArgs> Completed = delegate { };

        #endregion
    }
}